import{P as e,T as t,ut as n}from"./B603vO-13smUKN.js";import{gn as r,vn as i}from"./CIxmKYxc4tZcJF.js";import{n as a}from"./CEfFgyve1X3Nnc.js";function o(e,t={}){let{delay:n=100,trailing:r=!0,leading:i=!0}=t,a,o=0,s=0,c;function l(){return a?(clearTimeout(a),a=void 0,!0):!1}function u(...t){let u=Date.now(),d=u-o,f=()=>{s=0,o=Date.now(),e.apply(this,t)};if(c=f,d>n||!a){i&&(d>n?f():++s);let e=d>n?n:n-d;l(),o=u,a=setTimeout(()=>{l(),r&&(!i||s>0)&&c?.()},e)}else++s}return u.cancel=l,u.stop=()=>{l()&&c&&c()},u.immediate=async function(...t){l(),o=Date.now(),e.apply(this,t)},u.dispose=()=>u.stop(),u}function s(t,n={}){let{delay:r=100}=n,i,a=!1,o;function s(){i&&=(clearTimeout(i),void 0)}async function c(){try{if(s(),o!=null){let n=[...o];o=void 0,a=!0,await e(t(...n)),a=!1,o!=null&&(s(),i=setTimeout(c,r))}}catch{}}function l(...e){o=[...e],s(),a===!1&&(i=setTimeout(c,r))}async function u(...e){s(),o=[...e],await c()}return l.cancel=s,l.dispose=s,l.immediate=u,l}var c=6,l=n(`notification`),u=i([]),d=!1;function f(e){d=e}function p(e){let t=u.value.findIndex(t=>t.id===e);t>=0?(u.value[t]?.onClose?.(),u.value.splice(t,1)):l.warn(`Notification with id ${e} not found for closing`)}function m(e){e.timeout>0&&setTimeout(()=>{e.active=!1,p(e.id)},e.timeout),setTimeout(()=>{u.value.length>c&&u.value.pop()},1500),u.value.unshift(e)}function h(e){e.id||=t(`oui-notification`),e.active||=!0,e.icon||=`info`,e.mode||=`info`,e.timeout??=5*1e3;let n=e;if(n.action=()=>{n.onAction?.(),p(n.id)},n.action2=()=>{n.onAction2?.(),p(n.id)},n.close=()=>{n.onCancel?.(),p(n.id)},d)return m(n),n;let r=a();return Promise.resolve(r?.notify?r.notify({id:n.id,title:n.title,message:n.message,mode:n.mode}):!1).then(e=>{e===!1&&m(n)}).catch(()=>m(n)),n}function g(e){return h(e)}function _(e,t,n=-1){return g({icon:`warning`,mode:`error`,title:e,message:t,timeout:n})}var v=r([]);function y(e,t,n=-1){return v.unshift({title:e,message:t}),g({title:e,message:t,timeout:n})}export{f as a,u as i,_ as n,s as o,y as r,o as s,g as t};